﻿using Omniscient.Foundation.Data;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace Omniscient.TimeTracker.Data
{
    [DataContract()]
    public class TimeEntry: EntityBase
    {
        public TimeEntry()
            : base()
        {}

        public TimeEntry(Guid id, bool entityIsLoaded)
            : base(id, entityIsLoaded)
        {}

        [EntityProperty(EntityPropertyType.Value)]
        [DataMember()]
        public DateTime StartDateTime { get; set; }
        
        [EntityProperty(EntityPropertyType.Value)]
        [DataMember()]
        public DateTime EndDateTime { get; set; }

        /// <summary>
        /// Comments for the executed entry time. Comments are added after task is completed.
        /// </summary>
        [EntityProperty(EntityPropertyType.Value)]
        [DataMember()]
        public string Comments { get; set; }

        /// <summary>
        /// Parent task for the current time entry.
        /// </summary>
        [EntityProperty(EntityPropertyType.Reference, "TaskGuid")]
        [DataMember()]
        public Task Task { get; set; }

        /// <summary>
        /// Category is like: Analysis, Meeting, Development, Human ressource, IT        
        /// </summary>
        [EntityProperty(EntityPropertyType.Reference, "CategoryGuid")]
        [DataMember()]
        public Category Category { get; set; }
        
        /// <summary>
        /// Return how many time the current time entry was started
        /// </summary>
        /// <returns></returns>
        public String GetElapsedTime()
        {
            return (StartDateTime - DateTime.Now).TotalMinutes.ToString();
        }

        /// <summary>
        /// Gets or sets the resource that has worked for this time entry.
        /// </summary>
        [EntityProperty(EntityPropertyType.Reference, "ResourceGuid")]
        [DataMember()]
        public Resource Resource { get; set; }
    }
}
